DAY12:Complementary DNA


Posted by birdbirdmurmur on 2023-07-25

題目連結:

Complementary DNA

解法:

function DNAStrand(dna){
  return dna.replace(/[ACTG]/g, match =>{
    switch(match){
      case "A":
        return "T";
      case "T":
        return "A";
      case "C":
        return "G";
      case "G":
        return "C";
    }
  })
}

筆記:

替換字先想到replace()
/[ATCG]/g:找到所有A、T、C、G四個字母
switch()將傳遞進來的值通過case轉換成另外一個字


#javascript #Codewars #replace #switch







Related Posts

PyTorch 踩坑紀錄:one of the variables needed for gradient computation has been modified by an inplace operation

PyTorch 踩坑紀錄:one of the variables needed for gradient computation has been modified by an inplace operation

每日心得筆記 2020-06-24(三)

每日心得筆記 2020-06-24(三)

SQL-injection專論 (4) -- Blind SQL injection (2)

SQL-injection專論 (4) -- Blind SQL injection (2)


Comments